package com.java.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @function: 客房管理
 * @CreateTime: 2021/3/16 20:12
 * @author 孙昱松
 */
@Controller
public class HouseController {

    @Autowired
    private HouseService houseService;

    /**
     * 房间类型信息查询
     * @return
     */
    @RequestMapping("getHouseManage")
    @ResponseBody
    public PageInfo<Map<String, Object>> getHouseManage(@RequestParam(defaultValue = "1")int pageNum, @RequestParam(defaultValue = "5")int pageSize){

        PageHelper.startPage(pageNum,pageSize);
        List<Map<String,Object>> list = houseService.findRoomType();
        PageInfo<Map<String, Object>> mapPageInfo = new PageInfo<>(list);

        return mapPageInfo;
    }
    /**
     *  ajax获取房间类型信息
     */
    @RequestMapping("getAllRoomType")
    @ResponseBody
    public List<Map<String,Object>> getAllRoomType(){
        return houseService.findRoomType();
    }
    /**
     * 添加客房信息
     */
    @RequestMapping("addRoom")
    @ResponseBody
    public boolean addRoom(String roomnum,String roomstatus,Long roomtypeid){
        return houseService.saveRooms(roomnum,roomstatus,roomtypeid);
    }
    /**
     * 通过roomnum查询房间是否存在
     */
    @RequestMapping("getRoomByRoomnum")
    @ResponseBody
    public boolean getRoomByRoomnum(String roomnum){
        return houseService.getRoomByRoomnum(roomnum);
    }

    /**
     * 房间信息查询
     */
    @RequestMapping("getRoomInfo")
    @ResponseBody
    public  PageInfo<Map<String, Object>> getRoomInfo(@RequestParam(defaultValue = "1")int pageNum, @RequestParam(defaultValue = "5")int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Map<String, Object>> rooms = houseService.findRooms();
        PageInfo<Map<String, Object>> mapPageInfo = new PageInfo<>(rooms);

        return mapPageInfo;
    }

    /**
     * 空闲房间查询
     */
    @RequestMapping("getKXRoom")
    @ResponseBody
    public List<Map<String,Object>> getKXRoom(){
        return houseService.findRoomBystatus();
    }

    

}
